/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worldscale.xp.wspr.impl;

import net.worldscale.xp.wspr.IStringResourceMapper;
import net.worldscale.xp.wspr.StringResourceManager;

/**
 *
 * @author Kun
 */
public class ImplStrResManager extends StringResourceManager {

    private IStringResourceMapper mMapper;

    public ImplStrResManager() {
        mMapper = new MyMapper();
    }

    @Override
    public IStringResourceMapper getMapper() {
        return mMapper;
    }

    @Override
    public String getString(String key) {
        if (key == null) {
            return "[null]";
        }
        String value = mMapper.map(key);
        if (value == null) {
            value = key;
        }
        return value;
    }

    @Override
    public void setMapper(IStringResourceMapper mapper) {
        if (mapper != null) {
            mMapper = mapper;
        }
    }

    private static final class MyMapper implements IStringResourceMapper {

        public String map(String key) {
            if (key == null) {
                return "[null]";
            }
            return key;
        }
    }
}
